﻿namespace CommLib
{
    public class MessageCallLog : BluetoothMessage
    {
        public MessageCallLog(byte[] data, int length)
            : base(BtMessageType.CallLog, data, length)
        {
        }

        public CallLogType getCallLogType()
        {
            int val = int.Parse(mData[0]);

            if (val >= 0 && val < (int)CallLogType.Unknown)
            {
                return (CallLogType)val;
            }
            
            return CallLogType.Unknown;
        }

        public CallLogEntry[] getEntries()
        {
            CallLogEntry[] list = null;

            if ((mData.Length - 1) % CallLogEntry.FIELD_COUNT == 0)
            {
                list = new CallLogEntry[(mData.Length - 1) / CallLogEntry.FIELD_COUNT];

                int idx = 0;
                for (int i = 1; i < mData.Length; i += CallLogEntry.FIELD_COUNT)
                {
                    list[idx++] = new CallLogEntry(mData, i);
                }
            }

            return list;
        }
    }
}
